package com.zb.common.exception;

import com.zb.model.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class BaseExceptionHandler {

    //自定义异常
    @ExceptionHandler(CommonException.class)
    public Result<String> exceptionHandler(CommonException ex) {
        Integer code = ex.getCode();
        String message = ex.getMessage();
        return new Result(code, message);
    }

    // 捕获未捕获异常
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception ex){
        ex.printStackTrace();
        return Result.ERROR();
    }


}
